﻿using System;
using System.ComponentModel;
using System.Xml.Linq;

namespace YArchitech.MEP
{
	public class HYSystemOption
	{
		[Category("参数设置")]
		[DisplayName("沿程修正系数")]
		[DefaultValue(1.0)]
		public double FrictionFix { get; set; }

		[Category("参数设置")]
		[DisplayName("局部阻力修正系数")]
		[DefaultValue(1.0)]
		public double ShockFix { get; set; }

		[Category("参数设置")]
		[DisplayName("管壁粗糙度修正系数")]
		[DefaultValue(1.0)]
		public double RoughnessFix { get; set; }

		[Category("参数设置")]
		[DisplayName("管壁粗糙度(m)")]
		[DefaultValue(0.00015)]
		public double Roughness { get; set; }

		[Category("参数设置")]
		[DisplayName("运动黏度(㎡/s)")]
		[DefaultValue(1.57E-05)]
		public double Viscosity { get; set; }

		[Category("参数设置")]
		[DisplayName("空气密度(kg/m³)")]
		[DefaultValue(1.197803)]
		public double Density { get; set; }

		[Category("通过大气状态计算密度")]
		[DisplayName("大气压(Pa)")]
		[DefaultValue(101325)]
		public double AtmosphericPressure { get; set; }

		[Category("通过大气状态计算密度")]
		[DisplayName("相对湿度")]
		[DefaultValue(0.6)]
		public double RelativeHumidity { get; set; }

		[Category("通过大气状态计算密度")]
		[DisplayName("温度(℃)")]
		[DefaultValue(25)]
		public double Temperature { get; set; }

		[Category("阻力设置")]
		[DisplayName("是否采用默认末端阻力设置")]
		[DefaultValue(false)]
		public bool TerminalLossEnable { get; set; }

		[Category("阻力设置")]
		[DisplayName("默认阻力")]
		[DefaultValue(50)]
		public double TerminalLoss { get; set; }

		public HYSystemOption()
		{
			this.RoughnessFix = 1.0;
			this.FrictionFix = 1.0;
			this.ShockFix = 1.0;
			this.Roughness = 0.00015;
			this.Viscosity = 1.57E-05;
			this.Density = 1.197803;
			this.AtmosphericPressure = 101325.0;
			this.RelativeHumidity = 0.6;
			this.Temperature = 20.0;
			this.TerminalLossEnable = false;
			this.TerminalLoss = 50.0;
		}

		public virtual double CalDensity()
		{
			this.Density = Hydrokinetics.AtmosphericDensity(this.Temperature, this.RelativeHumidity, this.AtmosphericPressure);
			return this.Density;
		}

		public virtual void WriteXml(XElement xe)
		{
			xe.SetAttributeValue("FrictionFix", this.FrictionFix);
			xe.SetAttributeValue("ShockFix", this.ShockFix);
			xe.SetAttributeValue("RoughnessFix", this.RoughnessFix);
			xe.SetAttributeValue("Roughness", this.Roughness);
			xe.SetAttributeValue("Viscosity", this.Viscosity);
			xe.SetAttributeValue("Density", this.Density);
			xe.SetAttributeValue("AtmosphericPressure", this.AtmosphericPressure);
			xe.SetAttributeValue("RelativeHumidity", this.RelativeHumidity);
			xe.SetAttributeValue("Temperature", this.Temperature);
			xe.SetAttributeValue("FrictionFix", this.FrictionFix);
			xe.SetAttributeValue("TerminalLossEnable", this.TerminalLossEnable);
			xe.SetAttributeValue("TerminalLoss", this.TerminalLoss);
		}

		public virtual void ReadXml(XElement xe)
		{
			this.FrictionFix = xe.ToDouble("FrictionFix", 1.0);
			this.ShockFix = xe.ToDouble("ShockFix", 1.0);
			this.RoughnessFix = xe.ToDouble("RoughnessFix", 1.0);
			this.Roughness = xe.ToDouble("Roughness", 0.00015);
			this.Viscosity = xe.ToDouble("Viscosity", 1.57E-05);
			this.Density = xe.ToDouble("Density", 1.197803);
			this.AtmosphericPressure = xe.ToDouble("AtmosphericPressure", 101325.0);
			this.RelativeHumidity = xe.ToDouble("RelativeHumidity", 0.6);
			this.Temperature = xe.ToDouble("Temperature", 25.0);
			this.TerminalLossEnable = xe.ToBool("TerminalLossEnable", false);
			this.TerminalLoss = xe.ToDouble("TerminalLoss", 50.0);
		}
	}
}
